package com.ai.entity.server;

import com.ai.entity.BasePage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ServerPage extends BasePage<ServerPO> {

    @ApiModelProperty(value = "服务器名")
    private String nickname;

    @ApiModelProperty(value = "服务器IP")
    private String ip;

    @ApiModelProperty(value = "状态(1.开，2.关，-1.弃用)")
    private Integer state;

    @Override
    public QueryWrapper<ServerPO> getQuery(QueryWrapper<ServerPO> queryWrapper) {
        return super.getQuery(queryWrapper)
                .like((!StringUtils.isEmpty(nickname)), "nickname", nickname)
                .like((!StringUtils.isEmpty(ip)), "ip", ip)
                .eq((state != null && state != 0), "state", state)
                .gt((state == null || state == 0), "state", -1);
    }
}
